#ifndef __HOOK_INTERFACE_H__
#define __HOOK_INTERFACE_H__

#include "../common/common_utils.h"

extern "C"
{
	// ##################################################
	//                      接口定义
	// ##################################################
    typedef int (*socket_t)(int, int, int);
    extern socket_t socket_f;
    
    typedef int (*close_t)(int);
    extern close_t close_f;
    
    typedef int (*connect_t)(int, const sockaddr*, socklen_t);
    extern connect_t connect_f;
    
    typedef int (*accept_t)(int, struct sockaddr*, socklen_t*);
    extern accept_t accept_f;
    
    typedef int (*read_t)(int, void*, size_t);
    extern read_t read_f;
    
    typedef int (*write_t)(int, const void*, size_t);
    extern write_t write_f;
    
    typedef int (*send_t)(int, const void*, size_t, int);
    extern send_t send_f;
    
    typedef int (*recv_t)(int, void*, size_t, int);
    extern recv_t recv_f;
    
    typedef int (*poll_t)(struct pollfd*, nfds_t, int);
    extern poll_t poll_f;
    
    typedef unsigned int (*sleep_t)(unsigned int);
    extern sleep_t sleep_f;
    
    typedef int (*usleep_t)(useconds_t);
    extern usleep_t usleep_f;
    
    typedef int (*getsockopt_t)(int, int, int, void*, socklen_t*);
    extern getsockopt_t getsockopt_f;
    
    typedef int (*setsockopt_t)(int, int, int, const void*, socklen_t);
    extern setsockopt_t setsockopt_f;

    typedef int (*fcntl_t)(int, int, ...);
    extern fcntl_t fcntl_f;

    typedef int (*pipe_t)(int pipefd[2]);
    extern pipe_t pipe_f;

	// ##################################################
	//                      接口实现
	// ##################################################
    int socket(int domain, int type, int protocol);
    int close(int fd);
    int connect(int fd, const sockaddr* addr, socklen_t addrlen);
    int accept(int fd, struct sockaddr* addr, socklen_t* addrlen);
    ssize_t read(int fd, void* buf, size_t len);
    ssize_t write(int fd, const void* buf, size_t len);
    ssize_t send(int fd, const void* buf, size_t len, int flags);
    ssize_t recv(int fd, void* buf, size_t len, int flags);
    int poll(struct pollfd* fds, nfds_t nfds, int timeout);
    unsigned int sleep(unsigned int seconds);
    int usleep(useconds_t usec);
    int getsockopt(int fd, int level, int optname, void* optval, socklen_t* optlen);
    int setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen);
    int fcntl(int fd, int cmd, ...);
    int pipe(int pipefd[2]);
}

#endif

